package test.yuxizhou.actions;

import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.IWorkbenchWindowActionDelegate;
import test.yuxizhou.wizards.NewWizard;

public class GenWizardAction implements IWorkbenchWindowActionDelegate {
	private IWorkbenchWindow window;
	private IStructuredSelection selection;

	public GenWizardAction() {
	}

	public void run(IAction action) {		
		NewWizard newWizard = new NewWizard();
		newWizard.init(window.getWorkbench(), selection);
		WizardDialog dialog = new WizardDialog(window.getShell(), newWizard);
		dialog.create();
		dialog.open();
	}

	public void selectionChanged(IAction action, ISelection selection) {
		if (selection instanceof IStructuredSelection) {
			selection = (IStructuredSelection) selection;
		} else {
			selection = null;
		}
	}

	public void dispose() {
	}

	public void init(IWorkbenchWindow window) {
		this.window = window;
	}
}